import { Body, Controller, Get, Post, Res, HttpStatus, UploadedFile, UseInterceptors, HttpException, Query, Request } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import e, { Response } from 'express';
import { AnswerTemplate } from './answerTemplate.entity';
import { AnswerTemplateService } from './answerTemplate.service';
import {
  get,
  post
} from 'request'
import request from 'request'
import {join, resolve} from 'path'
import { createWriteStream } from 'fs';
import { ValidTokenInterceptor } from 'src/interceptor/validToken';

import {
  existsSync,
  mkdirSync
} from 'fs'

import {
  apibefore
} from '../../router'
import { ValidRSAInterceptor } from 'src/interceptor/validRSA';
@Controller(apibefore('/answerTemplate'))
@UseInterceptors(ValidTokenInterceptor)
export class AnswerTemplateController {
  constructor(private readonly service: AnswerTemplateService) {}

  @Post('create')
  @UseInterceptors(ValidRSAInterceptor)
  async create(@Body() data: AnswerTemplate,@Request() req){
    let template = new AnswerTemplate()
    template.wx_user = req.headers.wx_user
    template.title = data.title
    template.content = data.content
    template.create_time = new Date()
    template.update_time = new Date()
    return await this.service.create(template)
  }

  @Get('find_by_wx_user')
  async find_by_wx_user(@Request() req){
    return await this.service.findByWxUser(req.headers.wx_user)
  }
}
